﻿@using Apps.Web.Core;
@using Apps.Web;
@using Apps.Common;
@using Apps.Models.Sys;
@using Apps.Locale;
@{
    ViewBag.Title = "Spl_WareDetails";
    Layout = "~/Views/Shared/_Index_Layout.cshtml";
    List<permModel> perm = null;
}
<div id="uploadExcel" class="easyui-window" data-options="modal:true,closed:true,minimizable:false,shadow:false">
    <form name="form1" method="post" id="form1">
        <table>
            <tr>
                <th style="padding:20px;"> Excel：</th>
                <td style="padding:20px;">
                    <input name="ExcelPath" type="text" maxlength="255" id="txtExcelPath" readonly="readonly" style="width:200px" class="txtInput normal left">
                    <a href="javascript:$('#FileUpload').trigger('click').void(0);" class="files">@Resource.Browse</a>
                    <input class="displaynone" type="file" id="FileUpload" name="FileUpload" onchange="Upload('ExcelFile', 'txtExcelPath', 'FileUpload'); ">
                    <span class="uploading">@Resource.Uploading</span>
                </td>
            </tr>
        </table>
        <div class="endbtndiv">
            <a id="btnSave" href="javascript:ImportData123()" class="easyui-linkbutton btns">直接保存</a>
            <a id="btnReturn" href="javascript:$('#uploadExcel').window('close')" class="easyui-linkbutton btnc">@Resource.Cancel</a>
        </div>
    </form>
</div>
<div class="mvctool">
   <input id="txtQuery" placeholder="请输入关键字" type="text" class="searchText" />
    @Html.ToolButton("btnQuery", "fa fa-search", Resource.Query, ref perm, "Query", true)
    @Html.ToolButton("btnCreate", "fa fa-plus", Resource.Create, ref perm, "Create", true)
    @Html.ToolButton("btnEdit", "fa fa-pencil", Resource.Edit, ref perm, "Edit", true)
    @Html.ToolButton("btnDetails", "fa fa-list", Resource.Details, ref perm, "Details", true)
    @Html.ToolButton("btnDelete", "fa fa-trash", Resource.Delete, ref perm, "Delete", true)
    @Html.ToolButton("btnImport", "fa fa-level-down", Resource.Import, ref perm, "Import", true)

</div>
<table>
    <tr>
        <td style="vertical-align: top; width: 210px;padding-top:3px">
            <div id="p" class="easyui-panel" title="存货分类" style="width:205px;padding:10px;">
                @Html.Raw(ViewBag.GetWareCateogryTree)
            </div>

        </td>
        <td style="width:3px;">&nbsp;</td>
       @* <td style="padding: 3px">*@
        <td style="vertical-align:top">
            <table id="List"></table>
        </td>
    </tr>
</table>

<div id="modalwindow" class="easyui-window" style="width:800px; height:400px;" data-options="modal:true,closed:true,minimizable:false,shadow:false"></div>
@Html.Partial("~/Views/Shared/_Partial_AutoGrid.cshtml")
<script type="text/javascript">
    var id ="";
    function getSelected() {
        
        var node = $('#StructTree').tree('getSelected');
        if (node) {
            id = node.attributes.id;
            $("#List").datagrid("load", { category: id });
        }
    }

    $(function () {
        $('#List').datagrid({
            url: '@(Url.Action("GetList"))?category=root',
            //url: '@Url.Action("GetList")',
            width: SetGridWidthSub(220),
            methord: 'post',
            height: SetGridHeightSub(47),
            nowrap: true,
            fitColumns: false,
            sortName: 'CreateTime',
            sortOrder: 'desc',
            idField: 'Id',
            pageSize: 15,
            pageList: [15,20, 30, 40, 50],
            pagination: true,
            striped: true, //奇偶行是否区分
            singleSelect: true,//单选模式
            onLoadSuccess: function (data) {
                 @foreach(var r in perm){if(r.Category==2){@Html.Raw("$(this).datagrid('hideColumn','"+r.KeyCode+"');");}}//动态根据权限隐藏列
            },
            //rownumbers: true,//行号
            frozenColumns: [[
                { field: 'Id', title: '主键ID', width: 80,hidden:true },
                { field: 'Code', title: '编号', width: 120,sortable:true,halign: 'center' },
                { field: 'Name', title: '商品名称', width: 120,sortable:false,halign: 'center' },
                { field: 'Brand', title: '品牌', width: 80, sortable: true, halign: 'center' },
                { field: 'Size', title: '型号', width: 150, sortable: true, halign: 'center' },
                { field: 'WareCategoryId', title: '存货分类', width: 80, sortable: false, hidden: true, halign: 'center' },
                { field: 'Unit', title: '单位', width: 80, sortable: false, halign: 'center' },
                { field: 'WareCategoryName', title: '存货分类', width: 80 ,halign: 'center'},
            ]],
            @*onLoadSuccess: function (data) {
                @foreach(var r in perm){if(r.Category==2){@Html.Raw("$(this).datagrid('hideColumn','"+r.KeyCode+"');");}}//动态根据权限隐藏列
            },*@
            columns: [[
                                 { title: '基本信息', colspan: 6 },
                                 { title: '其他信息', colspan: 11 },
                                 { title: '多级价格', colspan: 5},
                                 { title: '图片', colspan: 5 }

            ], [
                { field: 'Lable', title: '存货标签', width: 80, sortable: false, halign: 'center' },
                { field: 'BuyPrice', title: '参考进价', width: 80, sortable: false, halign: 'center', align: 'right', formatter: function (value) { return MoneyFormatter(value) } },
                { field: 'SalePrice', title: '参考售价', width: 80,sortable:true ,halign: 'center',align:'right', formatter: function (value) { return MoneyFormatter(value) } },
                { field: 'RetailPrice', title: '零售价', width: 80,sortable:true ,halign: 'center',align:'right', formatter: function (value) { return MoneyFormatter(value) } },
                { field: 'Enable', title: '状态', width: 80, sortable: false, halign: 'center', formatter: function (value) { return EnableFormatter(value) } },
                { field: 'Remark', title: '备注', width: 80, sortable: false, halign: 'center', formatter: function (value) { return "<span class='exceed'>" + value + "</span>" } },
                { field: 'Vender', title: '供货商', width: 150, sortable: false, halign: 'center' },
                //{ field: 'Brand', title: '品牌', width: 80, sortable: false, halign: 'center' },
                { field: 'Color', title: '颜色', width: 80, sortable: false, halign: 'center' },
                { field: 'Material', title: '技术参数', width: 80, sortable: false, halign: 'center' },
                //{ field: 'Size', title: '型号', width: 80, sortable: false, halign: 'center' },
                { field: 'Weight', title: '重量', width: 80, sortable: false, halign: 'center' },
                { field: 'ComeFrom', title: '产地', width: 80, sortable: false, halign: 'center' },
                { field: 'UpperLimit', title: '最高库存', width: 80,sortable:true ,halign: 'center'},
                { field: 'LowerLimit', title: '最低库存', width: 80,sortable:true ,halign: 'center'},
                { field: 'PrimeCost', title: '参考成本', width: 80,sortable:true ,halign: 'center'},
                { field: 'CreateTime', title: '创建时间', width: 140,sortable:true ,halign: 'center'},
                { field: 'Price1', title: '一级价格', width: 80,sortable:true,halign: 'center',align:'right', formatter: function (value) { return MoneyFormatter(value) } },
                { field: 'Price2', title: '二级价格', width: 80,sortable:true,halign: 'center',align:'right', formatter: function (value) { return MoneyFormatter(value) } },
                { field: 'Price3', title: '三级价格', width: 80,sortable:true,halign: 'center',align:'right', formatter: function (value) { return MoneyFormatter(value) } },
                { field: 'Price4', title: '四级价格', width: 80,sortable:true,halign: 'center',align:'right', formatter: function (value) { return MoneyFormatter(value) } },
                { field: 'Price5', title: '五级价格', width: 80,sortable:true,halign: 'center',align:'right', formatter: function (value) { return MoneyFormatter(value) } },
                { field: 'Photo1', title: '照片1', width: 80, sortable: false, halign: 'center', formatter: function (value) { return ImgFormatter(value) } },
                { field: 'Photo2', title: '照片2', width: 80, sortable: false, halign: 'center', formatter: function (value) { return ImgFormatter(value) } },
                { field: 'Photo3', title: '照片3', width: 80, sortable: false, halign: 'center', formatter: function (value) { return ImgFormatter(value) } },
                { field: 'Photo4', title: '照片4', width: 80, sortable: false, halign: 'center', formatter: function (value) { return ImgFormatter(value) } },
                { field: 'Photo5', title: '照片5', width: 80, sortable: false, halign: 'center', formatter: function (value) { return ImgFormatter(value) } },


            ]]

        });
    });
    //ifram 返回
    function frameReturnByClose() {
        $("#modalwindow").window('close');
    }
    function frameReturnByReload(flag) {
        if (flag)
            $("#List").datagrid('load');
        else
            $("#List").datagrid('reload');
    }
    function frameReturnByMes(mes) {
        $.messageBox5s(Lang.Tip, mes);
    }
    $(function () {
        $("#btnCreate").click(function () {
            $("#modalwindow").html("<iframe width='100%' height='100%' scrolling='auto' frameborder='0'' src='@Url.Action("Create")'></iframe>");
            $("#modalwindow").window({ title: Lang.Create, width: 800, height: 600, iconCls: 'fa fa-plus' }).window('open');
        });
        $("#btnEdit").click(function () {
            var row = $('#List').datagrid('getSelected');
            if (row != null) {
                $("#modalwindow").html("<iframe width='100%' height='99%'  frameborder='0' src='@Url.Action("Edit")?id=" + row.Id + "&Ieguid=" + GetGuid() + "'></iframe>");
                $("#modalwindow").window({ title: '@Resource.Edit', width: 800, height: 600, iconCls: 'fa fa-pencil' }).window('open');
            } else { $.messageBox5s(Lang.Tip, '@Resource.PlaseChooseToOperatingRecords'); }
        });
        $("#btnDetails").click(function () {
            var row = $('#List').datagrid('getSelected');
            if (row != null) {
                $("#modalwindow").html("<iframe width='100%' height='98%' scrolling='auto' frameborder='0' src='@Url.Action("Details")?id=" + row.Id + "&Ieguid=" + GetGuid() + "'></iframe>");
                $("#modalwindow").window({ title: '@Resource.Details', width: 700, height: 400, iconCls: 'fa fa-list' }).window('open');
            } else { $.messageBox5s(Lang.Tip, '@Resource.PlaseChooseToOperatingRecords'); }
	        });
        $("#btnQuery").click(function () {
            var queryStr = $("#txtQuery").val();
            if (queryStr == null) {
                queryStr = "%";
            }
            $("#List").datagrid("load", { queryStr: encodeURI(queryStr) });

        });
        $("#btnImport").click(
            function () {
              


                    if (id == "") {
                        $.messageBox5s(Lang.Tip, "导入之前请选择到存放的类别");
                    } else {

                $("#txtExcelPath").val("");
                $("#uploadExcel").window({ title: '@Resource.Import', width: 450, height: 155, iconCls: 'fa fa-level-down' }).window('open');
            }
            }

            );
        $("#btnDelete").click(function () {
            var row = $('#List').datagrid('getSelected');
            if (row != null) {
                $.messager.confirm(index_lang_tip, '@Resource.YouWantToDeleteTheSelectedRecords', function (r) {
	                    if (r) {
	                        $.post("@Url.Action("Delete")?id=" + row.Id, function (data) {
	                            if (data.type == 1)
	                                $("#List").datagrid('load');
	                            $.messageBox5s(Lang.Tip, data.message);
	                        }, "json");

	                    }
	                });
	            } else { $.messageBox5s(Lang.Tip, '@Resource.PlaseChooseToOperatingRecords'); }
        });

    });

    function ImportData123()
    {

        showLoading();
        var url = "@Url.Action("Import")?filePath=" + $("#txtExcelPath").val() + "&categoryId=" + id;
        $.post(url, function(data) {
            if (data.type == 1)
            {
                $("#List").datagrid('load');
                $('#uploadExcel').window('close');
            }
            hideLoading();
            $.messageBox5s('提示', data.message);
        }, "json");
    }

</script>

